package com.sky.controller.admin;

import com.sky.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/shop")
@Slf4j
public class AdminShopController {

    private final String SHOP_STATUS = "SHOP_STATUS";
    @Autowired
    StringRedisTemplate stringRedisTemplate;

    /**
     * 获取营业状态
     * @return
     */
    @GetMapping("/status")
    public Result getStatus(){
        Integer shopStatus = Integer.valueOf(stringRedisTemplate.opsForValue().get(SHOP_STATUS));
        log.info("获取营业状态：{}",shopStatus == 1?"营业中":"打烊中");
        return Result.success(shopStatus);
    }


    /**
     * 设置营业状态
     * @return
     */
    @PutMapping("/{status}")
    public Result setStatus(@PathVariable("status") Integer status){
        log.info("设置营业状态：{}",status == 1?"营业中":"打烊中");
        stringRedisTemplate.opsForValue().set("SHOP_STATUS", String.valueOf(status));
        return Result.success();
    }
}
